package com.hjz.shequ;

import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class MainActivity extends AppCompatActivity {

    private WebView mWebView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }

    private void initView(){
        mWebView= (WebView) findViewById(R.id.wv_view);
        String url="http:www.jiaoshouzhi.com";
        WebSettings wSet = mWebView.getSettings();
        //设置是否支持JS交互，不设置页面显示不出来
        wSet.setJavaScriptEnabled(true);
        //设置适应屏幕
        wSet.setUseWideViewPort(true);
        wSet.setLoadWithOverviewMode(true);
        //支持缩放
        wSet.setSupportZoom(true);
        //设置数据格式，这样能在一定程度上节省资源
        wSet.setDefaultTextEncodingName("UTF-8");
        //隐藏原生缩放控件
        wSet.setDisplayZoomControls(false);
        wSet.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
        mWebView.loadUrl(url);

        mWebView.setWebChromeClient(new WebChromeClient() {
            @Override
            public void onReceivedTitle(WebView view, String title) {
                super.onReceivedTitle(view, title);

            }

            @Override
            public void onProgressChanged(WebView view, int newProgress) {
                super.onProgressChanged(view, newProgress);
//                pbBar.setProgress(newProgress);
//                if (100 == newProgress) {
//                    pbBar.setVisibility(View.GONE);
//                }
            }
        });

        mWebView.setWebViewClient(new WebViewClient() {

            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                super.onPageStarted(view, url, favicon);
//                pbBar.setVisibility(View.VISIBLE);
            }

            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
//                pbBar.setVisibility(View.GONE);
            }

            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                mWebView.loadUrl(url);
                return true;
            }
        });
    }
}
